<template>
  <div>
  <div class="outmain ba_f">
    <div class="shuju_title mar_b20">
      <div class="shuju_title_text">
        <span>门店设置</span>
      </div>
    </div>
    <el-form ref="form" :model="form" label-width="100px">
<!--      <el-form-item label="商品设置">-->
<!--        <el-checkbox-group v-model="form.goodsSet">-->
<!--          <el-checkbox label="1">允许门店修改价格</el-checkbox>-->
<!--          <el-checkbox label="2">允许门店修改库存</el-checkbox>-->
<!--          <el-checkbox label="3">允许门店添加商品</el-checkbox>-->
<!--        </el-checkbox-group>-->
<!--      </el-form-item>-->
      <el-form-item label="自动进店">
        <el-radio-group v-model="form.enterStore">
          <el-radio label="1">新用户自动定位到最近门店，老用户默认进上次访问过的门店</el-radio>
          <el-radio label="2">新老用户都自动定位到最近门店</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="显示距离">
        <el-radio-group v-model="form.showType">
          <el-radio label="1">按区域显示</el-radio>
          <el-radio label="2">按距离显示</el-radio>

        </el-radio-group>
          <div class="yb_margin lh16">如按区域显示，则门店列表将按城市区域筛选</div>

      </el-form-item>
      <el-form-item label="显示距离" v-if="form.showType=='2'">
        <el-input v-model="form.distance" type="number" placeholder="请输入显示距离">
          <template slot="append">km</template>
        </el-input>
      </el-form-item>
    </el-form>
  </div>
    <div class="mar_t20 ba_f pad_20 t_c">
      <el-button type="primary" @click="submitForm">保存</el-button>
    </div>
  </div>
</template>
<script>
  import {getConfig, postConfig} from "@/api/setup";
  export default {
    created() {
      this.init();
    },
    data () {
      return {
        form: {
          goodsSet: [],
          enterStore: '1',
          showType: '1',
          distance: '',
        },
      }
    },
    methods: {
      async init() {
        const {data} = await getConfig({ident:'storeSet'});
        this.form2 = this.form
        this.form = Object.assign(this.form2, data);
      },
      submitForm() {
        this.$refs["form"].validate(async (valid) => {
          if (valid) {
            this.form.ident = 'storeSet'
            const {msg} = await postConfig(this.form);
            this.$baseMessage(msg, "success");
            this.init();
          } else {
            return false;
          }
        });
      },
    },
  }
</script>
